package com.jy.api.domain;

/**
 * 三方支付交易状态
 * Created by hanxi on 2018/8/24.
 */
public class TradeState {
    private String state;

    private TradeState(String state) {
        this.state = state;
    }

    public final static TradeState SUCCESS = new TradeState("SUCCESS");
    // 转入退款
    public final static TradeState REFUND = new TradeState("REFUND");
    // 未支付
    public final static TradeState NOTPAY = new TradeState("NOTPAY");
    public final static TradeState CLOSED = new TradeState("CLOSED");
    // 已撤销
    public final static TradeState REVOKED = new TradeState("REVOKED");
    // 已撤销
    public final static TradeState REVERSE = new TradeState("REVERSE");
    // 用户支付中
    public final static TradeState USERPAYING = new TradeState("USERPAYING");
    // 支付失败(其他原因，如银行返回失败)
    public final static TradeState PAYERROR = new TradeState("PAYERROR");

    public static TradeState valueOf(String state) {
        return new TradeState(state);
    }

    public boolean isNeedQuery() {
        if (state.equals("REFUND") || state.equals("NOTPAY") || state.equals("USERPAYING")) {
            // 转入退款的最终状态应该是已撤销。因此需要继续查询，直到最终状态为止
            return true;
        } else {
            return false;
        }
    }

}
